package com.moto.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.moto.Vo.CarVo;
import com.moto.entity.Car;
import com.moto.entityDto.*;
import com.moto.interceptor.BaseContext;
import com.moto.mapper.CarMapper;
import com.moto.service.ICarService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moto.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 车辆表 服务实现类
 * </p>
 *
 * @author afei
 * @since 2023-08-28
 */
@Service
public class CarServiceImpl extends ServiceImpl<CarMapper, Car> implements ICarService {

    @Autowired
    private CarMapper carMapper;
    /**
     * 新增摩托车
     * @param carCatDto
     */
    @Override
    public void addCar(CarCatDto carCatDto) {
        //设置摩托状态
        carCatDto.setIsDelete(1);

        //设置摩托图片

        //设置修改时间修改员工
        carCatDto.setUpdateDate(LocalDateTime.now());
        carCatDto.setUpdateId(BaseContext.getCurrentId());
        carMapper.addCar(carCatDto);
        int id = carMapper.findCarMaxId();
        System.out.println("id:::::"+id);
        carCatDto.setId(id);
        carMapper.addCarCat(carCatDto);

    }


    /**
     * 根据评分查询摩托
     */
    @Override
    public List<CarDto> orderMarkCar() {
        return carMapper.orderMarkCar();
    }

    /**
     * 摩托车分页查询
     * @param carPageDto
     * @return
     */
    @Override
    public PageResult findAllCar(CarPageDto carPageDto) {
        PageHelper.startPage(carPageDto.getPage(), carPageDto.getPageSize());
        Page<CarVo> page = carMapper.findAllCar(carPageDto);
        return new PageResult(page.getTotal(),page.getResult());
    }

    /**
     * 摩托车根据id修改信息
     * @param carUpdateDto
     */
    @Override
    public void updateCarById(CarUpdateDto carUpdateDto) {
        carMapper.updateCarById(carUpdateDto);
    }

    @Override
    public List<Car> userFindCar(CarSelectDto carSelectDto) {
        return carMapper.userFindCar(carSelectDto);
    }

    /**
     * 用户选择车辆
     */



}
